BX.namespace("BX.UI");if(typeof BX.UI.SelectorMenuItem==="undefined"){BX.UI.SelectorMenuItem=function(){this._parent=null;this._settings={};this._emitter=null};BX.UI.SelectorMenuItem.prototype={initialize:function(e){this._settings=e;this._emitter=new BX.Event.EventEmitter;this._emitter.setEventNamespace("BX.UI.SelectorMenuItem");var t=BX.prop.getFunction(BX.prop.getObject(this._settings,"events",{}),"select",null);if(t){this.addOnSelectListener(t)}},getValue:function(){return BX.prop.getString(this._settings,"value","")},getText:function(){var e=BX.prop.getString(this._settings,"text","");return BX.type.isNotEmptyString(e)?e:this.getValue()},isEnabled:function(){return BX.prop.getBoolean(this._settings,"enabled",true)},isDefault:function(){return BX.prop.getBoolean(this._settings,"default",false)},createMenuItem:function(e){if(BX.prop.getBoolean(this._settings,"delimiter",false)){return{delimiter:true}}e=!!e;var t=this.getText();if(!!e){t=BX.util.htmlspecialchars(t)}return{text:t,onclick:function(){this._emitter.emit("select",{item:this})}.bind(this),className:BX.prop.getString(this._settings,"className","")}},addOnSelectListener:function(e){this._emitter.subscribe("select",e)},removeOnSelectListener:function(e){this._emitter.unsubscribe("select",e)}};BX.UI.SelectorMenuItem.create=function(e){var t=new BX.UI.SelectorMenuItem;t.initialize(e);return t}}if(typeof BX.UI.SelectorMenu==="undefined"){BX.UI.SelectorMenu=function(){this._id="";this._settings={};this._items=[];this._encodeItems=true;this._emitter=null;this._popup=null;this._isOpened=false;this._itemSelectHandler=BX.delegate(this.onItemSelect,this)};BX.UI.SelectorMenu.prototype={initialize:function(e,t){this._id=BX.type.isNotEmptyString(e)?e:"ui_selector_menu_"+Math.random().toString().substring(2);this._settings=t?t:{};this._encodeItems=!!this.getSetting("encodeItems",true);var i=this.getSetting("items");i=BX.type.isArray(i)?i:[];this._items=[];for(var n=0;n<i.length;n++){var s=BX.UI.SelectorMenuItem.create(i[n]);s.addOnSelectListener(this._itemSelectHandler);this._items.push(s)}this._emitter=new BX.Event.EventEmitter;this._emitter.setEventNamespace("BX.UI.SelectorMenu")},getId:function(){return this._id},getSetting:function(e,t){return this._settings.hasOwnProperty(e)?this._settings[e]:t},getItems:function(){return this._items},setupItems:function(e){this._items=[];for(var t=0;t<e.length;t++){var i=BX.UI.SelectorMenuItem.create(e[t]);i.addOnSelectListener(this._itemSelectHandler);this._items.push(i)}},isOpened:function(){return this._isOpened},open:function(e){if(this._isOpened){return}var t=[];for(var i=0;i<this._items.length;i++){var n=this._items[i];if(n.isEnabled()){t.push(n.createMenuItem(this._encodeItems))}}BX.PopupMenu.show(this._id,e,t,{closeByEsc:true,offsetTop:0,offsetLeft:0,events:{onPopupShow:BX.delegate(this.onPopupShow,this),onPopupClose:BX.delegate(this.onPopupClose,this),onPopupDestroy:BX.delegate(this.onPopupDestroy,this)}});this._popup=BX.PopupMenu.currentItem},close:function(){if(this._popup&&this._popup.popupWindow){this._popup.popupWindow.close()}},addOnSelectListener:function(e){this._emitter.subscribe("select",e)},removeOnSelectListener:function(e){this._emitter.unsubscribe("select",e)},onItemSelect:function(e){this.close();this._emitter.emit("select",{menu:this,item:e.data["item"]})},onPopupShow:function(){this._isOpened=true},onPopupClose:function(){if(this._popup){if(this._popup.popupWindow){this._popup.popupWindow.destroy()}}},onPopupDestroy:function(){this._isOpened=false;this._popup=null;if(typeof BX.PopupMenu.Data[this._id]!=="undefined"){delete BX.PopupMenu.Data[this._id]}}};BX.UI.SelectorMenu.create=function(e,t){var i=new BX.UI.SelectorMenu;i.initialize(e,t);return i}}
//# sourceMappingURL=selector.map.js